#ifndef ZXPLMODULESTAT_H
#define ZXPLMODULESTAT_H

#include <QString>
#include <QObject>
#include <QxPLIdentifier.h>
#include <QTimer>
#include <ZModuleSettings.h>
#include <QxPLMessage.h>
#include <ZigbusMessage.h>
#include <QxPLUtils.h>

/**
   @brief The ZxPLModuleStat class
 */
class ZxPLModuleStat  : public QObject {
    Q_OBJECT
private:
    static const int DEFAULT_WARNING_INTERVAL = 1;
    static const int DEFAULT_HEARTBEAT_INTERVAL = 5;
    static const int CONFIGLESS_HEARTBEAT_INTERVAL = 1;
    static const int DEFAULT_PING_INTERVAL = 4;

    QString name;
    QString alias;
    bool alive;
    int heartbeatInterval;
    int pingInterval;
    QTimer* pingTimer;
    QTimer* heartbeatTimer;
    bool configured;
    //ZModuleSettings settings;

public:
    ZxPLModuleStat(const QString& moduleName, QObject* parent = 0);
    ZxPLModuleStat(const QString& moduleName, int heartbeatInterval, int pingInterval = DEFAULT_PING_INTERVAL, QObject* parent = 0);
    //ZxPLModuleStat(const ZModuleSettings& settings, bool configured, QObject* parent = 0);
    ~ZxPLModuleStat();

    const QString& getName() const { return name; }
    void setName(const QString& name) { this->name = name; }
    bool isAlive() const { return alive; }
    void setAlive(bool b) { alive = b; }
    int getPingInterval() const { return pingInterval; }
    void setPingInterval(int interval) { pingInterval = interval; }
    int getHeartbeatInterval() const { return heartbeatInterval; }
    void setHeartbeatInterval(int interval) { heartbeatInterval = interval; }
    const QString& getAlias() const { return alias; }
    void setAlias(const QString& alias) { this->alias = alias; }
    bool isConfigured() const { return configured; }
    void setConfigured(bool b) { configured = b; }

    QString toString() const;

public slots:
    void sendHeartbeat();
    void onPingTimerTimeout();
    void start();
    void stop();
    void reset();
    void kill();


signals:
    void iAmDead(QString moduleId);
    void iAmWarn(QString moduleId);
    void iAmAlive(QString moduleId);
    void messageGenerated(QxPLMessage);
    void messageGenerated(ZigbusMessage);
};

#endif // ZXPLMODULESTAT_H
